package com.lanou.beautifulwardrobe.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.bartoszlipinski.recyclerviewheader.RecyclerViewHeader;
import com.lanou.beautifulwardrobe.Home.Adapter.IntroFRecyclerViewAdapter;
import com.lanou.beautifulwardrobe.R;
import com.lanou.beautifulwardrobe.entify.IntroData;

/**
 * Created by dllo on 15/11/6.
 */
public class IntroFActivity extends Activity implements View.OnClickListener {
    private RecyclerView recyclerView;
    private GridLayoutManager manager;
    private IntroFRecyclerViewAdapter adapter;
    private IntroData data;
    private ImageButton introFBack;
    private TextView introFTitle, introFDecription;
    private RecyclerViewHeader introFHeader;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intro);
        this.data = (IntroData) getIntent().getSerializableExtra("data");
        initView();
        initData();
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.introRecyclerView);
        manager = new GridLayoutManager(this, 1);
        adapter = new IntroFRecyclerViewAdapter();
        introFBack = (ImageButton) findViewById(R.id.introFBack);
        introFTitle = (TextView) findViewById(R.id.introFTitle);
        introFDecription = (TextView) findViewById(R.id.introFDecription);
        introFHeader = (RecyclerViewHeader) findViewById(R.id.introFHeader);
        listener();
    }

    private void listener() {
        introFBack.setOnClickListener(this);
    }

    private void initData() {
        recyclerView.setLayoutManager(manager);
        introFHeader.attachTo(recyclerView, true);
        introFTitle.setText(data.getShort_title());
        introFDecription.setText(data.getDescription());
        adapter.addData(data.getContent().getData().getElements());
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        finish();
    }
}
